package cn.edu.zut.pms.faker;

import com.github.javafaker.Faker;
import java.sql.*;
import java.util.Locale;
import java.util.Random;

public class FakerLogisticsGoodsAmount {
    public static void main(String[] args) {
        // 数据库连接信息（请根据实际环境修改）
        String url = "jdbc:mysql://192.168.17.150:3306/soil?allowPublicKeyRetrieval=true&useSSL=false";
        String user = "root";
        String password = "000000";

        // 创建Faker实例
        Faker faker = new Faker(new Locale("zh_CN"));
        Random random = new Random();

        // 定义货品类型（与源表dwd_logistics_data保持一致）
        String[] products = {"电子产品", "服装鞋帽", "食品饮料", "家居用品", "图书文具", "美妆个护"};

        try (Connection connection = DriverManager.getConnection(url, user, password)) {
            // 先清空表中现有数据（可选）
            String truncateSql = "TRUNCATE TABLE ads_logistics_goods_amount";
            try (Statement statement = connection.createStatement()) {
                statement.execute(truncateSql);
            }

            // 插入数据的SQL语句
            String insertSql = "INSERT INTO ads_logistics_goods_amount (" +
                    "product, sales_amount" +
                    ") VALUES (?, ?)";

            try (PreparedStatement preparedStatement = connection.prepareStatement(insertSql)) {
                for (String product : products) {
                    // 根据货品类型设置不同的销售金额范围（符合实际商品价值特性）
                    double salesAmount;
                    switch (product) {
                        case "电子产品":
                            salesAmount = faker.number().randomDouble(2, 500000, 2000000); // 高价值商品
                            break;
                        case "家居用品":
                            salesAmount = faker.number().randomDouble(2, 300000, 1000000);
                            break;
                        case "服装鞋帽":
                        case "美妆个护":
                            salesAmount = faker.number().randomDouble(2, 200000, 800000);
                            break;
                        case "食品饮料":
                            salesAmount = faker.number().randomDouble(2, 150000, 600000);
                            break;
                        case "图书文具":
                            salesAmount = faker.number().randomDouble(2, 50000, 300000); // 低价值商品
                            break;
                        default:
                            salesAmount = faker.number().randomDouble(2, 100000, 500000);
                    }

                    // 设置参数
                    preparedStatement.setString(1, product);
                    preparedStatement.setDouble(2, salesAmount);

                    preparedStatement.executeUpdate();
                }
                System.out.println("数据插入完成，共插入 " + products.length + " 条货品销售金额记录");
            } catch (SQLException e) {
                e.printStackTrace();
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}